﻿using B.S.BasicData.Domain;
using B.S.BasicData.ErrorCode;
using B.S.BasicData.Infrastructure.Interfance;
using B.S.BasicData.Read.Apilication.Common.MenuRole;
using MediatR;

namespace B.S.BasicData.Read.Apilication.Handler.MenuRole
{
    public class GetOneRoleCommandHandle:IRequestHandler<GetOneRoleCommand, ApiResult<List<int>>>
    {
        private readonly IBaseRepository<MenuRoleModel> baseRepository;
        private readonly IBaseRepository<MenuModel> MenuDal;
        private readonly IBaseRepository<RoleModel> RoleDal;

        public GetOneRoleCommandHandle(IBaseRepository<MenuRoleModel> baseRepository, IBaseRepository<MenuModel> menuDal, IBaseRepository<RoleModel> roleDal)
        {
            this.baseRepository = baseRepository;
            MenuDal = menuDal;
            RoleDal = roleDal;
        }

        public Task<ApiResult<List<int>>> Handle(GetOneRoleCommand request, CancellationToken cancellationToken)
        {
            ApiResult<List<int>> result = new ApiResult<List<int>>();
            var info = baseRepository.GetAll().Where(x => x.RoleId == request.RoleId).Select(x=>x.MenuId);

            result.Code = ApiEnum.Success;
            result.Message = "显示成功";
            result.Data = info.ToList();
            return Task.FromResult(result);
        }

    }
}
